import requests
from api.login import loginapi
# 把请求封装后 传入对象 一条一条的执行
from common.common_assert import asset


class Test_log():
    # 也可以把方法放到此类里面 进行调用
    # @classmethod
    # def tesk(cls,body):
    #     url = "http://ihrm-test.itheima.net/api/sys/login"
    #     heads = {"Content-Type": "application/json"}
    #     req = requests.post(url, headers=heads, json=body)
    #     return req

    # 把公共断言方法抽取出去 在不同的接口中使用




    def test_01(self):
        # url="http://ihrm-test.itheima.net/api/sys/login"
        # heads={"Content-Type": "application/json"}
        body={"mobile": "13800000002", "password": "123456"}
        # 调用登录方法 将数据放进去 保存到resp
        resp=loginapi.login(body)

# 调用函数asset 传入参数  这是公共的

        asset(resp,200,"操作成功！",10000,True)
        # assert resp.status_code==200
        # assert resp.json().get("message")=="操作成功！"
        # assert resp.json().get("code")==10000
        # assert resp.json().get("success")==True

        # 一条测试用例一个方法 密码错误
    def test_02(self):
        # url = "http://ihrm-test.itheima.net/api/sys/login"
        # heads = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "12345"}
        resp=loginapi.login(body)
        print(resp.json())

        asset(resp, 200, "用户名或密码错误", 20001, False)
        # assert resp.status_code == 200
        # assert resp.json().get("message") == "用户名或密码错误"
        # assert resp.json().get("code") == 20001
        # assert resp.json().get("success") == False

    # 手机号不存在
    def test_03(self):
        # url = "http://ihrm-test.itheima.net/api/sys/login"
        # heads = {"Content-Type": "application/json"}
        body = {"mobile": "18952369878", "password": "12345"}
        resp=loginapi.login(body)
        print(resp.json())
        asset(resp, 200, "用户名或密码错误", 20001, False)


        # assert resp.status_code == 200
        # assert resp.json().get("message") == "用户名或密码错误"
        # assert resp.json().get("code") == 20001
        # assert resp.json().get("success") == False

